<?php
namespace jy_yuyue;
defined('BY_JYA') or exit('error');
/*
	工具类
*/
class model extends \plugin{
	public function payresult($order,$payresult=array()){
		pdo_update('jy_yuyue_order',array('transid'=>$payresult['transaction_id'],'status'=>'1','pay'=>$payresult['fee']),array('id'=>$order['id']));
		model('jy_yuyue/order')->order_pai($post);
		model('jy_yuyue/order')->order_sys($post);
		return true;
	}
	//核销
	public function self_verify($orderid,$clerk_id,$selfnumber){
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$order_verify=$this->pdo_get('order',array('id'=>$orderid));
		if(!$order_verify){
			exi('预约码不存在！','error','jy_yuyue/worker_hexiao/');
		}
		if($order_verify['status']>=2){
			exi('预约码已被使用或已过期！','error','jy_yuyue/worker_hexiao/');
		}
		//按消费码核销
		$update=array(
				'status'=>1,
				'clerk_id'=>$clerk_id,
				'verifytime'=>TIMESTAMP,
		);
		$self=array(
				'uniacid'=>$_SESSION['uniacid'],
				'orderid'=>$orderid,
				'merchid'=>$order_verify['merchid'],
				'number'=>$selfnumber,
				'clerk_id'=>$clerk_id,
				'status'=>1,
				'createtime'=>time()
		);
		$this->pdo_insert('order_self',$self);
		$this->order_receive($order_verify['id']);
		return true;
	}
	public function order_receive($order_id,$ismsg=false){
		$update=array('status'=>2);
		$this->update('order',$update,array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
	public function order_cancel($order_id,$ismsg=false){
		pdo_update('jy_yuyue_order',array('status'=>3),array('id'=>$order_id,'uniacid'=>$_SESSION['uniacid']));	
		return true;
	}
	public function get_days(){
		//日期
		$data=array();
		$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
		$days=$days>0?$days:7;
		for($i=0;$i<$days;$i++){
			$data[]=array(
				'ymd'=>date("Y-m-d",strtotime("+".$i." day")),
				'riqi'=>date("m-d",strtotime("+".$i." day")),
				'xinq'=>"星期".$weekarray[date("w",strtotime(date("Y-m-d",strtotime("+".$i." day"))))],
				'isshow'=>1
			);
		}
		return $data;
	}
}